<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>2691：图中图</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">图中图</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">图中图</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                图中图                </h1>
                <p>时间限制：30s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：128MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><div id="ptit" class="probtitle" style="text-align: center; padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: 微软雅黑, 黑体, 'Times New Roman'; font-size: 24pt; font-weight: bold; padding-top: 0px"></div>
<div id="pres" style="text-align: center; padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: 宋体, 'Times New Roman'; font-size: 14px; vertical-align: middle; font-weight: bold; padding-top: 0px"></div>
<div id="pcont1" style="text-align: left; padding-bottom: 0px; margin: 20px 0px 0px; padding-left: 0px; padding-right: 0px; font-family: 宋体, 'Times New Roman'; padding-top: 0px">
<div class="pdcont" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: 'Times New Roman', 宋体; color: rgb(32,0,0); font-size: 14px; padding-top: 0px">　　Answer在看过碟中谍后，对&ldquo;X中X&rdquo;很感兴趣，于是想探究&ldquo;图中图&rdquo;。<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />
&ldquo;图中图&rdquo;的外图是一张由M个大节点组成的有K条边(无重边和自环)的无向无权图(不一定连通)，外图中的每个大节点的内部又是一张由若干条边组成的无向有权图。<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />
Answer想要构一张&ldquo;图中图&rdquo;，对大节点之间的边可以随便连K条，对每个大节点内部的无向图，Answer有一种生成方法：<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />
1. 先确定一个长度为N的序列A<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />
2. 对于每个大节点，确定一个在A中的区间[l<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i&nbsp;</sub>, r<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i</sub>]<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />
3. 那么在第i个大节点中，<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />
边数=sigma(sum<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">x</sub>+num<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">x</sub><sup style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">3</sup>) 区间[l<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i&nbsp;</sub>, r<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i</sub>]中存在x<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />
其中sum<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">x</sub>为在区间[l<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i&nbsp;</sub>, r<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i</sub>]中比x小的数字个数，num<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">x</sub>为区间[l<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i&nbsp;</sub>, r<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i</sub>]中等于x的数字个数。<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />
设t为在区间[l<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i&nbsp;</sub>, r<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i&nbsp;</sub>]中出现的不重复的数字个数，那么每条边上的权值可以取1~t的任意正整数。<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />
现在，Answer想要求出在给M,K,序列A和每个大节点的区间[l<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i&nbsp;</sub>, r<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i&nbsp;</sub>]的情况下，有多少张不同的&ldquo;图中图&rdquo;，由于方案数可能很大，你只需要输出方案数模P后的答案。<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />
*对于大节点，Answer只关心边的情况，而不关心点的情况，每个大节点中的边是有标号的，两个方案不同当且仅当，M个大节点的连接状况不同或者至少其中有一个大节点的其中一条边的权值不同。</div>
<div class="pdsec" style="border-bottom: rgb(187,187,187) 1px solid; padding-bottom: 4px; background-color: rgb(248,248,255); margin: 8px 0px 4px; padding-left: 6px; padding-right: 0px; font-family: 微软雅黑, 黑体, 华文细黑; font-size: 16px; font-weight: bold; padding-top: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px"></div>
<div class="pdcont" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: 'Times New Roman', 宋体; color: rgb(32,0,0); font-size: 14px; padding-top: 0px"></div>
</div>
<p></p></p><hr/><h3>输入格式</h3><p><div class="pdsec" style="border-bottom: rgb(187,187,187) 1px solid; text-align: left; padding-bottom: 4px; background-color: rgb(248,248,255); margin: 8px 0px 4px; padding-left: 6px; padding-right: 0px; font-family: 微软雅黑, 黑体, 华文细黑; font-size: 16px; font-weight: bold; padding-top: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px"></div>
<div class="pdcont" style="text-align: left; padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: 'Times New Roman', 宋体; color: rgb(32,0,0); font-size: 14px; padding-top: 0px">　　输入的第一行包含四个正整数N,M,P,K。<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />
第二行包含N个正整数A<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i</sub>。<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />
以下M行，每行包含两个正整数l<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i</sub>,r<sub style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">i</sub>。<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />
意义如上。</div>
<div class="pdsec" style="border-bottom: rgb(187,187,187) 1px solid; text-align: left; padding-bottom: 4px; background-color: rgb(248,248,255); margin: 8px 0px 4px; padding-left: 6px; padding-right: 0px; font-family: 微软雅黑, 黑体, 华文细黑; font-size: 16px; font-weight: bold; padding-top: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px"></div>
<div class="pdcont" style="text-align: left; padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: 'Times New Roman', 宋体; color: rgb(32,0,0); font-size: 14px; padding-top: 0px"></div>
<p></p></p><hr/><h3>输出格式</h3><p><p></p>
<div></div>
<div>
<div class="pdcont" style="text-align: left; padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: 'Times New Roman', 宋体; color: rgb(32,0,0); font-size: 14px; padding-top: 0px">　　输出一个整数，表示方案数模P后的值。</div>
<div class="pdsec" style="border-bottom: rgb(187,187,187) 1px solid; text-align: left; padding-bottom: 4px; background-color: rgb(248,248,255); margin: 8px 0px 4px; padding-left: 6px; padding-right: 0px; font-family: 微软雅黑, 黑体, 华文细黑; font-size: 16px; font-weight: bold; padding-top: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px"></div>
<div class="pdcont" style="text-align: left; padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: 'Times New Roman', 宋体; color: rgb(32,0,0); font-size: 14px; padding-top: 0px"></div>
</div></p><hr/><h3>样例输入</h3><pre>5 3 22 2
1 2 1 3 1
1 3
2 4
3 5
</pre><hr/><h3>样例输出</h3><pre>14
</pre><hr/><h3>提示</h3><p><div>样例说明</div>
<div>　　外图中有3个大节点，那么连2条边，有3种连法</div>
<div>　　第一个大节点中有11条边，每条边可以取值1~2</div>
<div>　　第二个大节点中有6条边，每条边可以取值1~3</div>
<div>　　第三个大节点中有11条边，每条边可以取值1~2</div>
<div>　　所以总方案数模22得14</div>
<div>数据规模和约定</div>
<div>　　设P=p1 c1 *p2c2 *&hellip;*ptct ，pi为质数。</div>
<div>　　对于30%的数据，满足N,M&le;1000,M2&lt;P&lt;10^9且P是质数</div>
<div>　　另有20%的数据，满足N,M&le;1000</div>
<div>　　对于100%的数据,满足N,M&le;50000 , K&le;M*(M-1)/2 , 0&le;ai&le;10^9</div>
<div>pi^ci &le;100000 , P&le;10^9</div>
<p></p></p><hr/><h3>题目来源</h3><p>没有写明来源</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=2691" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=2691" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>